<template>
	<view class="form-content">
		<uni-forms ref="form" :modelValue="formData">
			<uni-forms-item required="true" name="stuId" label="学号">
				<uni-easyinput type="number" v-model="formData.stuId" placeholder="请输入学号" />
			</uni-forms-item>
			<uni-forms-item name="sport" label="是否喜欢运动">
				<radio-group name="sport" v-model="formData.sport">
					<label>
						<radio value="1" /><text>是</text>
					</label>
					<label>
						<radio value="0" /><text>否</text>
					</label>
				</radio-group>
			</uni-forms-item>
			<uni-forms-item name="fitnes" label="是否喜欢健身">
				<radio-group name="fitnes" v-model="formData.fitnes">
					<label>
						<radio value="1" /><text>是</text>
					</label>
					<label>
						<radio value="1" /><text>否</text>
					</label>
				</radio-group>
			</uni-forms-item>
			<uni-forms-item name="game" label="是否喜欢打游戏">
				<radio-group name="game" v-model="formData.game">
					<label>
						<radio value="1" /><text>是</text>
					</label>
					<label>
						<radio value="0" /><text>否</text>
					</label>
				</radio-group>
			</uni-forms-item>
			<uni-forms-item name="night" label="是否喜欢熬夜">
				<radio-group name="night" v-model="formData.night">
					<label>
						<radio value="1" /><text>是</text>
					</label>
					<label>
						<radio value="0" /><text>否</text>
					</label>
				</radio-group>
			</uni-forms-item>
			<uni-forms-item name="bright" label="是否喜欢早起">
				<radio-group name="bright" v-model="formData.bright">
					<label>
						<radio value="1" /><text>是</text>
					</label>
					<label>
						<radio value="0" /><text>否</text>
					</label>
				</radio-group>
			</uni-forms-item>
			<uni-forms-item name="reading" label="是否喜欢看书">
				<radio-group name="reading" v-model="formData.reading">
					<label>
						<radio value="0" /><text>是</text>
					</label>
					<label>
						<radio value="1" /><text>否</text>
					</label>
				</radio-group>
			</uni-forms-item>
			<view class="btn-content">
				<button size="mini" type="primary" @click="submit">提交</button>
			</view>
		</uni-forms>
	</view>
</template>

<script>
	import { addHobby } from "@/api/system/hobby"
	
	export default {
		data() {
			return {
				formData: {
					stuId: 0,
					sport: 0,
					fitnes: 0,
					game: 0,
					night: 0,
					bright: 0,
					reading: 0
				}
			}
			// rules:{
			// 	name: {
			// 	  rules: [{
			// 	    required: true,
			// 	    errorMessage: '姓名不能为空'
			// 	  }]
			// 	},
			// 	gender: {
			// 	  rules: [{
			// 	    required: true,
			// 	    errorMessage: '性别不能为空'
			// 	  }]
			// 	}
			// }
		},
		onReady() {
		  // this.$refs.form.setRules(this.rules)
		},
		methods: {
			submit() {
				this.$refs.form.validate().then(res=>{
					addHobby(this.formData).then(response => {
						uni.$emit('query', {e: 1})
						this.$modal.msgSuccess("提交成功")
						uni.navigateBack()
					})
				}).catch(err =>{
					this.$modal.errorMessage("提交失败");
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
		
		.form-content{
			margin: 10px;
			padding: 10px;
			.btn-content{
				display: flex;
				justify-content: center
			}
		}
	}

</style>
